import MarkdownViewer from "../../../../components/MarkdownViewer";
import React, {useEffect, useState} from "react";
import {ArticleControllerService, ArticleVo} from "../../../../service";
import {useSearchParams} from "react-router-dom";
import {Toast} from "@douyinfe/semi-ui";


const ArticleMdViewView:React.FC=()=>{
    const [value,setValue]=useState<ArticleVo>({});
    const [searchParams,serSearchParams]=useSearchParams();
    const loadData=async ()=>{
        const id=parseInt(searchParams.get("id")|| "0");
        if(id==null){
            return;
        }
        const res = await ArticleControllerService.getArticleById({
            id: id,
        });
        if(!res.data){
            Toast.error("获取文章信息失败:"+res.message);
            return;
        }
        setValue(res.data);
    }
    useEffect(()=>{
       loadData();
    },[])
    return (
        <div style={{
            margin: '10px 40px'
        }}>
            <MarkdownViewer value={value.content || ""}/>
        </div>
    )
}
export default ArticleMdViewView;
